package br.unifor.cct.mia.initialize;

import br.unifor.cct.mia.evolutionary.HugeScaleGenotype;
import br.unifor.cct.mia.ga.Ga;
import br.unifor.cct.mia.ga.util.HugeScaleGene;
import br.unifor.cct.mia.util.Methods;

public class HugeScaleRandomInitialize implements Initialize {

	public Object execute(Object value) {	
		Object[] o = (Object[]) value;
		Ga ga = (Ga)o[0];
		Integer nBits = (Integer)o[1];

		ga.population = new HugeScaleGenotype[ga.configurations.getPopsize()+1];

		for (int i = 0; i < ga.configurations.getPopsize(); i++) {
			ga.population[i] = new HugeScaleGenotype(ga.configurations, nBits);

			ga.population[i].setFitness(0);
			ga.population[i].setSelectProbability(0);                 

			HugeScaleGene genes[] = new HugeScaleGene[ga.configurations.getNvars()];
			for (int j = 0; j < ga.configurations.getNvars(); j++) { 

				HugeScaleGene gene = new HugeScaleGene(nBits);

				for ( int x=0; x<nBits; x++ ) {
					gene.getBits()[x] = Methods.randIntValue(0,1);   
				}

				genes[j] = gene;
			}       
		}

		return ga.population;
	}

}
